package com.itheima.test;

import java.sql.SQLOutput;
import java.util.Scanner;

public class StringTest1 {
    /*
        模拟用户登录，一共三次机会
        字符串截取
        char[] su=username.toCharArray();
        char su2=username.charAt(0);
        String su3=username.substring(3);
        String su4=username.substring(2,5);
        字符串替换
        String su5=username.replace("dm","dnm");
        字符串切割
        String s="192,168,16,1";
        String[] sArr=s.split(",");
     */
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);

        String username="admin";
        char[] su=username.toCharArray();
        char su2=username.charAt(0);
        String su3=username.substring(3);
        String su4=username.substring(2,5);
        String su5=username.replace("dm","dnm");
        String password="123456";

        for (int i = 1; i <=3; i++) {
            System.out.println("请输入用户名：");
            String inputUsername=sc.nextLine();
            System.out.println("请输入密码：");
            String inputPassword=sc.nextLine();
            if(inputUsername.equals(username)&&inputPassword.equals(password)){
                System.out.println("密码正确");
                break;
            }else{
                if(i==3){
                    System.out.println("大爷走好");
                }else {
                    System.out.println("密码错误，您还剩"+(3-i)+"次机会");
                }

            }
        }
    }
}
